	********************************************************************************
	****
	**** Date: 04.25.2022							 
	**** Update: 07.11.2023					 
	**** Author: JW josephgwright@gmail.com 				 	
	**** NOTE: This program has been executed in Stata 18.0	 
	**** 
	**** Using data files in $dir: 
	****
	****  	pers-use.dta
	**** 	GLP-person-18-07-29.dta
	****	CCS_Data_Wave1_v4.0.sav
	****  	vdem-parties-merge.dta
	****	whogov.dta
	****	leadermatch.dta
	****
	*********************************************************************************
		capture log close
		log using Ch3.log, replace

	******************************
	**** Set directory, seed *****
	******************************
		set more off 
		set matsize 1000
		global seed ="984353"
		set scheme plotplain
		cd "$dir"
 
		net from http://radyakin.org/transfer/usespss/beta   /* translates SPSS data to .dta for Stata */
	************************************************************************************************************
	****  How are personalist parties organized? support group, funders, and nominations and local strength ****
	************************************************************************************************************
			use pers-use,clear
			global d = "persparty"
			gen proportional= v2elparlel==1 | v2elparlel==3
			gen mixed =  v2elparlel==2
			gen s = year==min | v2xel_elecpres==1|  v2xel_elecparl==1
			
			*** Funded by party leader ***
			sum v2pafunds_6 
			xi:glm v2pafunds_6 i.period $d if s==1,fam(bin)link(probit)cluster(cowcode)			
			margins,dydx($d)
			est store org1
			xi:glm v2pafunds_6 i.pregion i.period proportional mixed pres ivdem ld $d if s==1,fam(bin)link(probit)cluster(cowcode)	
			margins,dydx($d)
			est store org2
			twoway (hist persparty,col(gs12)yscale(range(0 12)axis(2))yaxis(2)bin(50) ///
				ylab(0 "",axis(2)nolabels noticks) ytitle("",axis(2)) yscale(range(0 100)axis(2))) ///
				(lpolyci v2pafunds_6 persparty if s==1,bw(.175) ytitle(Leader funds party) ///
				 yscale(alt)yscale(range(0.25))ylab(.0(0.1)0.3, axis(1)) ///
				xtit(Party personalism)legend(off)tit(Leader funds party,size(large)) saving(h1.gph,replace) ///
				yline(.1706446,lcol(blue*.5))  text(.1795 .3 "Leader funds mean",size(vsmall)))
			xi:glm v2pafunds_6 i.pregion i.period proportional mixed pres ivdem ld $d i_populism ///
				if s==1,fam(bin)link(logit)cluster(cowcode)	
			est store porg1
			margins,dydx($d i_populism)
			
			***  Party nominations controlled by leader ***
			gen leadcontrol =  v2panom_ord==0 if v2panom_ord~=.
			tab  v2elloelsy leadcontrol
			gen sys =v2elloelsy
			recode sys (2=1) (3=4)(9 10=8)
  			xi:glm leadcontrol i.period $d if s==1,fam(bin)link(probit)cluster(cowcode)			
			margins,dydx($d)
			est store org3
			xi:glm leadcontrol i.pregion i.period proportional mixed pres ivdem ld $d if s==1,fam(bin)link(probit)cluster(cowcode)	
			margins,dydx($d)
			est store org4
			twoway (hist persparty,col(gs12)yscale(range(0 12)axis(2))yaxis(2)bin(50) ///
				ylab(0 "",axis(2)nolabels noticks) ytitle("",axis(2)) yscale(range(0 100)axis(2))) ///
				(lpolyci leadcontrol persparty if s==1,bw(.25) ytitle(Leader controls party nominations) ///
				 yscale(alt)yscale(range(0 .2))ylab(0(0.1)0.2, axis(1)) ///
				xtit(Party personalism)legend(off)tit(Leader controls party nominations,size(large)) saving(h2.gph,replace) ///
				yline(.0819964,lcol(blue*.5))text(.09 .1 "Leader control mean",size(vsmall)))
				* Footnote on populism adjustment *
			xi:glm leadcontrol i.pregion i.period proportional mixed pres ivdem ld $d i_populism ///
				if s==1,fam(bin)link(logit)cluster(cowcode)
			est store porg2
			margins,dydx($d i_populism)

			*** Local party strength ***
			alpha v2palocoff v2paactcom,std item gen(localstrength)
			qui sum localstrength 
			replace localstrength= (localstrength+abs(r(min)))
			qui sum localstrength
			replace localstrength=localstrength/r(max)
   			xi:glm localstrength i.period $d if s==1,fam(bin)link(probit)cluster(cowcode)			
			margins,dydx($d)
			est store org5
			xi:glm localstrength i.pregion i.period proportional mixed pres ivdem ld $d if s==1,fam(bin)link(probit)cluster(cowcod)	
			margins,dydx($d)
			est store org6
			twoway (hist persparty,col(gs12)yscale(range(0 12)axis(2))yaxis(2)bin(50) ///
				ylab(0 "",axis(2)nolabels noticks) ytitle("",axis(2)) yscale(range(0 100)axis(2))) ///
				(lpolyci localstrength persparty if s==1,bw(.25) ytitle(Local party strength) ///
				 yscale(alt)yscale(range(.595 .705))ylab(.6(0.05)0.7, axis(1)) ///
				xtit(Party personalism)legend(off)tit(Local party strength,size(large)) saving(h3.gph,replace) ///
				 yline(.6564862,lcol(blue*.5))  text(.654 .1 "Local strength mean",size(vsmall))  )	 
			xi:glm localstrength i.pregion i.period proport mixed pres ivdem ld $d i_populism ///
				if s==1,fam(bin)link(logit)cluster(cowcod)
				est store porg3
			margins,dydx($d i_populism)
			
			  * Plots for figure *
			gr combine h2.gph h1.gph h3.gph,xsize(5) ysize(2) col(3)iscale(.7)
			gr export "$dir\golden\Ch3-Persparty-Control.pdf",as(pdf)replace 
			
			*** Within estimator plot results ***
			gen e=.
			gen hi=.
			gen lo=.
			gen n =_n
			local i =1
			local var = "leadcontrol v2pafunds_6 localstrength"
			foreach v of local var {		
				qui xi: reghdfe `v' ivdem ld persparty i.period if s==1,a(cowcode) cluster(lid)
				nlcom _b[$d],post
				mat e = e(b)
				mat v = e(V)
				mat list e
				mat list v
				local b=e[1,1] 
				di `b'
				local se = sqrt(v[1,1])
				di `se'
				replace e =`b' if n==`i'
				replace hi = `b' + 1.96* `se' if n==`i'
				replace lo = `b' - 1.96* `se'  if n==`i'
				local i = `i'+1
			}
			twoway (rspike hi lo n if n<=3) (scatter e n if n<=3,msym(O)ytit({&beta}{sub:Party Personalist})yline(0,lcol(red)) ///
				xlab( 1 `""Leader nominates" "candidates""' 2 `""Leader" "funds party""' 3  `""Local party" "strength""') ///
				xscale(range(0.8 3.2))xtit("")note(95% CI,size(vsmall)pos(8)ring(0))legend(off)title(Leader control over party) ///
				subtitle(Within estimator,size(small)))
			gr export "$dir\golden\Ch3-Persparty-Control-Within.pdf",as(pdf)replace 

		* Plot estimates *
			label  var ld  `""Democracy" "age      ""'
			label  var persparty  `""{bf:Party}     " "{bf:personalism}""'
			label  var pres      `" "Presidential  " "(Parliamentary)""'
			label  var ivdem  `""Initial   " "democracy" "level    ""'
			label  var proportional  `" "Proportional " "(Majoritarian)""'
			label  var mixed  `" "Mixed      " "(Majoritarian)""'
			label var i_populism `""{bf:Party}     " "{bf:populism}""'
			coefplot (org1, msymbol(d))(org2,mfcolor(gs1)msymbol(circle)) (porg1,mfcolor(gs1)msymbol(T)), order(persparty)  ///
				drop(_cons _Iperiod_* _Iv2elparle_3 _Ipregion* period* ) xline(0) msymbol(d) mfcolor(white) grid(glcolor(gs15)) ///
				levels(90) legend(lab(2 "Baseline")lab(4 "Covariate adjustment")lab(6 "+ populism")  order(2 4 6) ///
				size(small) pos(6) col(3) ring(1)) xsize(2) ysize(2) xlab(-5(1)2)  ///
				xtitle("        Coefficient estimate", size(small))  ///
				ciopts(lwidth(thin)) aspectratio(1) scale(.85)  ///
				title(Leader funds party, size(large) height(3)) ///
				saving(h1.gph,replace)
			coefplot (org3, msymbol(d))(org4,mfcolor(gs1) msymbol(circle)) (porg2,mfcolor(gs1)msymbol(T)), order(persparty)  ///
				drop(_cons _Iperiod_* _Iv2elparle_3 _Ipregion* period*) xline(0) msymbol(d) mfcolor(white) grid(glcolor(gs15)) ///
				levels(90) legend(lab(2 "Baseline")lab(4 "Covariate adjustment")lab(6 "+ populism")  order(2 4 6) ///
				size(small) pos(6) col(3) ring(1)) xsize(2) ysize(2) xlab(-5(1)3)  ///
				xtitle("        Coefficient estimate", size(small))  ///
				ciopts(lwidth(thin)) aspectratio(1) scale(.85)  ///
				title(Leader controls party nominations, size(large) height(3)) ///
				saving(h2.gph,replace)
			coefplot (org5, msymbol(d))(org6,mfcolor(gs1) msymbol(circle)) (porg3,mfcolor(gs1)msymbol(T)), order(persparty)  ///
				drop(_cons _Iperiod_* _Iv2elparle_3 _Ipregion* period*) xline(0) msymbol(d) mfcolor(white) grid(glcolor(gs15)) ///
				levels(90) legend(lab(2 "Baseline")lab(4 "Covariate adjustment")lab(6 "+ populism")  order(2 4 6) ///
				size(small) pos(6) col(3) ring(1)) xsize(2) ysize(2) xlab(-1.6(.4)1.2)  ///
				xtitle("        Coefficient estimate", size(small))  ///
				ciopts(lwidth(thin)) aspectratio(1) scale(.85)  ///
				title(Local party strength, size(large) height(3)) ///
				saving(h3.gph,replace)
			gr combine h1.gph h2.gph h3.gph,xsize(4) ysize(8) col(1)iscale(.95) ///
				 note("Geographic region and time period FEs estimated but not reported." "Cluster-robust standard errors used to calculate confidence intervals.",size(small)pos(6))  
			gr export "$dir\golden\T-Persparty-Party-Control-Estimates.pdf",as(pdf)replace 
		
	
 **********************************************************************
 *** Elites experience using the Global Leadership Project data set ***
 ********************************************************************** 
			use "$dir\pers-use.dta",clear
			sort cowcode year,
			save, replace
			clear all
			use "$dir\GLP-person-18-07-29.dta"
			drop if person_office_start_year==0
			drop if person_office_start_year>2013
			drop if person_office_start_year<1955

			gen cowcode =.
			qui do cowcodes
			replace cowcode=437 if country=="Cote d'Ivoire (Ivory Coast)"
			replace cowcode=732 if country=="Korea, South"
			replace cowcode=359 if country=="Moldova, Republic of"
			replace cowcode=347 if country=="Kosovo"
			replace cowcode=200 if country=="United Kingdom (Great Britain)"
			tab country if cowcode==.
			drop if cowcode==.
			gen year=2013
			sort cowcode year
			merge cowcode year using "$dir\pers-use.dta"
			drop if year~=2013
			tab _merge
			keep if _merge==3
			drop _merge
			/*  
			Missing countries in GLP:
			cowcode	country
			475	Nigeria
			713	Taiwan
			771	Bangladesh
			790	Nepal
			*/

			* Variables *
			gen exp_missing = polexp==.
			gen exp_party=polexp==8
			xtile xage = age, nq(8)
			recode xage (.=0)
			gen tenure = year-person_office_start_year 
			gen tt = ln(1+(tenure))
			gen tx= tenure 
			replace tx = 25 if tenure>25 & tenure~=.
			qui sum populism 
			qui replace populism = (populism +abs(r(min)))/(r(max)+abs(r(min)))

			* Sample: non-backbenchers *
			*gen s = 1
			gen s = office1~=6 & polexp~=. & persparty~=. & exp_party~=.
			recode s (0=1) if power==1 | power==3  /* include most powerful even if backbenchers */
			recode s (1=0) if office1==1 /* exclude executives, who are the leaders */
			hist tenure if s==1
			tab exp_party if s==1
			egen num = count(year) if s==1,by(cowcode)
			hist num

			* Regional distribution in sample *
			label def region 1 "Eastern Europe and Central Asia" 2 "Latin America and the Caribbean"  ///
				3 "Middle East and North Africa" 4 "Sub-Saharan Africa" ///
				5 "Western Europe and North America" 6 "Asia and Pacific" ,replace
			label val pregion region
			egen c = count(ld) if s==1,by(country)
			egen t = tag(country) if c~=. & s==1
			table pregion if t==1, stat(mean c)  
			egen r = count(ld) if s==1 & t==1,by(pregion) 
			table pregion if s==1, stat(mean r)  
			drop c t r

			 * Partial plots *
			qui reg exp_party num ld ivdem i.region if s==1
			predict yexper if e(sample)==1,res
			qui reg tx num ld ivdem i.region  if s==1
			predict ytenure if e(sample)==1,res
			qui reg persparty num ld ivdem i.region  if s==1
			predict xpersparty if e(sample)==1,res
			  
			qui sum exp_part if s==1
			replace yexper=yexper+r(mean)
			qui sum  tx if s==1
			replace ytenure = r(mean) + ytenure
			qui sum persparty if s==1
			replace xpersparty = xpersparty+r(mean)
			replace xpersparty = (xpersparty -.1335)/.7155
			sum yexper ytenure if s==1
			sum xpersparty persparty if s==1
			 
			twoway (lpolyci yexper xpersparty,bw(.15) xlab(0(.2)1) yline(0.42)ytit("Probability selected from party (partial)") ///
				xtit("Party personalism (partial)")legend(off)tit(Elite with party experience)saving(h1.gph,replace) ///
				text(.43 .7 "Average level",size(vsmall)))
			twoway (lpolyci ytenure xpersparty,bw(.15) xlab(0(.2)1)yline(4.82)ytit("Years of experience (partial)") ///
				xtit("Party personalism (partial)")legend(off)tit(Elite years of experience)saving(h2.gph,replace) ///
				text(4.85 .7 "Average level",size(vsmall))ylab(4(1)6))
			gr combine h1.gph h2.gph,xsize(8)iscale(.8) ///
				tit(Personalist parties have fewer elites from the party and elites with less experience)
			gr export "$dir\golden\Ch3-GLP-Elite-Experience.pdf",as(pdf)replace 
			erase h1.gph 
			erase h2.gph
			drop yexper ytenure xpersparty

			********************
			* Party experience *
			********************
			replace num = num/100
			xi:logit exp_party num persparty ld if s==1, cluster(cowcode)
			est store party0
			xi:logit exp_party num persparty ld ivdem if s==1, cluster(cowcode) 
			est store party1
			xi:logit exp_party num persparty ld ivdem pres if s==1, cluster(cowcode) 
			est store party2
			xi:logit exp_party num persparty ld ivdem lpop l1gdp if s==1, cluster(cowcode)
			est store party3
			xi:logit exp_party num persparty ld ivdem i.xage male edulevel i.power i.office1 if s==1, cluster(cowcode)
			est store party4
			xi:logit exp_party num persparty ld ivdem i_populism if s==1, cluster(cowcode)
			est store party5
			xi:logit exp_party num persparty ld ivdem i.region if s==1, cluster(cowcode)
			est store party6
			margins,dydx(persparty)  /* reported margins */
			
			label var persparty `""Ruling party" "{bf:personalism}""'
			label var ld "Democracy age"
			label var ivdem `""Initial     " "democracy""'
			label var lpop "Population"
			label var l1gdp "GDP pc"
			label var i_populism `""Ruling party" "populism   ""'
			label var num `""# of elite " "in country""'
			label var pres `""Presidential" "system""'
			coefplot(party0, msymbol(O)mcol(gs1))(party1, msymbol(T)mcol(gs1))(party2, msymbol(S)mcol(gs1)) ///
				(party3, msymbol(D)mcol(gs1)) ///
				(party4, msymbol(O)mcol(gs11))(party5, msymbol(T)mcol(gs11))(party6, msymbol(S)mcol(gs11)), ///
				drop(_cons male edulevel  _I* pres lpop l1gdp) ///
				grid(glcolor(gs15))xline(0,lpattern(dash)) ///
				xtitle(Coefficient estimates) order(persparty ld ivdem i_populism)level(95 90) ///
				title("Elites with Party experience", ///
				size(medium)height(6)) legend(lab(3 "Baseline") lab(6 "+ Initial democracy") lab(9 "+ Presidential system") ///
				lab(12 "+ GDP, Population") lab(15 "+ Elite covariates")lab(18 "+ Populism") lab(21 "+ Region FE")  ///
				pos(6)ring(1)col(2)) xsize(2) ysize(3.5) mlabel format(%9.2g) ///
				mlabsize(vsmall)mlabposition(2)mlabgap(*.65)
			gr export "$dir\golden\T-GLP-party-experience.pdf",as(pdf)replace 

			* Margins when adjusting for party populism *
			qui logit exp_party num persparty ld ivdem i.region i_populism  if s==1, cluster(cowcode)
			margins,dydx(persparty)
			margins,dydx(i_populism)

			gen noexp = polexp==1 if polexp~=.
			xi:logit noexp num persparty ld if s==1, cluster(cowcode)
			est store no0
			xi:logit noexp num persparty ld ivdem if s==1, cluster(cowcode) 
			est store no1
			xi:logit noexp num persparty ld ivdem pres if s==1, cluster(cowcode) 
			est store no2
			xi:logit noexp num persparty ld ivdem lpop l1gdp if s==1, cluster(cowcode)
			est store no3
			xi:logit noexp num persparty ld ivdem i.xage male edulevel i.power i.office1 if s==1, cluster(cowcode)
			est store no4
			xi:logit noexp num persparty ld ivdem i_populism if s==1, cluster(cowcode)
			est store no5
			xi:logit noexp num persparty ld ivdem i.region if s==1, cluster(cowcode)
			est store no6
			margins,dydx(persparty) /* reported margins */
			
 
			coefplot(no0, msymbol(O)mcol(gs1))(no1, msymbol(T)mcol(gs1))(no2, msymbol(S)mcol(gs1)) (no3, msymbol(D)mcol(gs1)) ///
				(no4, msymbol(O)mcol(gs11))(no5, msymbol(T)mcol(gs11))(no6, msymbol(S)mcol(gs11)), ///
				drop(_cons male edulevel  _I* pres lpop l1gdp) ///
				grid(glcolor(gs15))xline(0,lpattern(dash)) ///
				xtitle(Coefficient estimates) order(persparty ld ivdem i_populism)level(95 90) ///
				title("Elites with No political experience", ///
				size(medium)height(6)) legend(lab(3 "Baseline") lab(6 "+ Initial democracy") lab(9 "+ Presidential system") ///
				lab(12 "+ GDP, Population") lab(15 "+ Elite covariates")lab(18 "+ Populism") lab(21 "+ Region FE")  ///
				pos(6)ring(1)col(2)) xsize(2) ysize(3.5) mlabel format(%9.2g) ///
				mlabsize(vsmall)mlabposition(2)mlabgap(*.65)
			gr export "$dir\golden\T-GLP-no-experience.pdf",as(pdf)replace 

			* Margins when adjusting for party populism *
			qui logit noexp num persparty ld ivdem i.region i_populism  if s==1, cluster(cowcode)
			margins,dydx(persparty)
			margins,dydx(i_populism)
			 
			********************
			* Elite experience *
			********************
			nbreg tenure persparty ld if s==1, cluster(cowcode)
			est store tenure0
			nbreg tenure persparty ld ivdem if s==1, cluster(cowcode) 
			est store tenure1
			nbreg tenure persparty ld ivdem pres if s==1, cluster(cowcode) 
			est store tenure2
			nbreg tenure persparty ld ivdem lpop l1gdp if s==1, cluster(cowcode)
			est store tenure3
			nbreg tenure persparty ld ivdem i.xage male edulevel i.power i.office1 if s==1, cluster(cowcode)
			est store tenure4
			nbreg tenure persparty ld ivdem i_populism if s==1, cluster(cowcode)
			est store tenure5
			nbreg tenure persparty ld ivdem i.region if s==1, cluster(cowcode)
			est store tenure6
			qui predict xnb
			twoway lpolyci xnb persparty,bw(.125)legend(off)xtit(Party personalism)ytit(Years)
			drop xnb

			* Margins *
			qui nbreg tenure persparty ld ivdem i.pregion i_populism if s==1, cluster(cowcode)
			qui centile persparty if e(sample)==1,centile(5 95)
			local c1 = r(c_1)
			local c2 = r(c_2)
			margins,at(persparty=(`c1' `c2'))predict(n)
			margins,at(persparty=(`c1' `c2'))predict(n)	contrast(atcontrast(r._at))
 			qui centile i_populism if e(sample)==1,centile(5 95)
			local c1 = r(c_1)
			local c2 = r(c_2)
			margins,at(i_populism=(`c1' `c2'))predict(n)
			margins,at(i_populism=(`c1' `c2'))predict(n)contrast(atcontrast(r._at))	

		  * Kitchen sink, unreported *
			logit exp_party persparty num ld ivdem i.xage male edulevel i.power i.office1 lpop ///
				l1gdp pres popul if s==1,cluster(cowcode) 
			nbreg tenure persparty num ld ivdem i.xage male edulevel i.power i.office1 lpop ///
				l1gdp pres popul lnparty if s==1,cluster(cowcode) 
 
		
*********************************************************************************************************************
******** Comparative Candidate Survey (CCS) to examine candidate political experience & nomination control **********
*********************************************************************************************************************
			use "$dir\pers-use.dta",clear
			sort v2paid year,
			save, replace
			clear all
			set more off 
			set matsize 1000
			global seed ="984353"
			set scheme plotplain
			usespss "$dir\CCS_Data_Wave1_v4.0.sav",clear
		
		*******************************
		**** Variable construction ****
		*******************************
			rename t1 countryid
			rename t3 year
			rename t8 elected
			rename t10 districtmagnitude
			rename t11 ballottype
			rename t12 incentive  /* continuous rank, but not equal interval */

			* Demographic data *
			recode e1 (1=1) (2=0) (.a .b .c=.),gen(male)
			recode e2 (.a .b .c=.),gen(birthyr)
			replace birthyr=. if birthyr<100
			gen age = year-birthyr
			hist age

			* Is the party leader too powerful *
			sum d7c
			gen partyleadertoopowerful = ((d7c*-1)+5)/4
			tab d7c partyleadertoopowerful
			 
			 * Political experience *
			recode a1 (97=.),gen(party_num)
			gen partytime = year-a2
			replace partytime=0 if a2==0  /* never joined a party */
			gen sqpartytime = partytime^(1/2)
			swilk sqpartytime
			gen candidate = a4a1==1 | a4a2 ==1 | a4a3 ==1 | a4a4 ==1 | a4a5 ==1 | a4a6 ==1  ///
				if a4a1~=. | a4a2~=. | a4a3~=. | a4a4~=. | a4a5~=. | a4a6~=. 
			recode a5a (1=1) (2=0) (.a .b .c=.),gen(exp_leg)
			recode a5b (.a .b .c=.) ,gen(yrs_exp_leg)
			replace yrs_exp_leg =0 if exp_leg==0
			recode a6a (1=1) (2=0) (.a .b .c=.),gen(exp_party)
			recode a6b (.a .b .c=.) ,gen(yrs_exp_party)
			replace yrs_exp_party =0 if exp_party==0

			gen yrs_exp_any = yrs_exp_leg if yrs_exp_leg~=. 
			replace yrs_exp_any = yrs_exp_party if (yrs_exp_party>yrs_exp_leg & yrs_exp_leg~=. &  yrs_exp_party~=.) | yrs_exp_leg==.
			gen exp_any = exp_leg==1   if exp_leg~=. 
			replace exp_any= exp_party if exp_leg==.

			local var = "leg party any"
			foreach v of local var {
				replace yrs_exp_`v' = ln(1+(yrs_exp_`v'^(1/2)))
				swilk yrs_exp_`v'
			}

		****************************************
		***** Code for V-Parties partyids ******
		****************************************
			gen v2paid=.
			replace v2paid = 	.	if countryid==	1	& year==	2007	& a1==	4
			replace v2paid = 	1209	if countryid==	1	& year==	2007	& a1==	5
			replace v2paid = 	1209	if countryid==	1	& year==	2010	& a1==	2
			replace v2paid = 	424	if countryid==	1	& year==	2007	& a1==	2
			replace v2paid = 	424	if countryid==	1	& year==	2010	& a1==	1
			replace v2paid = 	.	if countryid==	1	& year==	2007	& a1==	8
			replace v2paid = 	.	if countryid==	1	& year==	2007	& a1==	7
			replace v2paid = 	486	if countryid==	1	& year==	2007	& a1==	1
			replace v2paid = 	.	if countryid==	1	& year==	2010	& a1==	3
			replace v2paid = 	.	if countryid==	1	& year==	2007	& a1==	3
			replace v2paid = 	.	if countryid==	1	& year==	2007	& a1==	6
			replace v2paid = 	599	if countryid==	14	& year==	2008	& a1==	5
			replace v2paid = 	.	if countryid==	14	& year==	2008	& a1==	7
			replace v2paid = 	463	if countryid==	14	& year==	2008	& a1==	4
			replace v2paid = 	.	if countryid==	14	& year==	2008	& a1==	6
			replace v2paid = 	1659	if countryid==	14	& year==	2008	& a1==	3
			replace v2paid = 	.	if countryid==	14	& year==	2008	& a1==	14
			replace v2paid = 	.	if countryid==	14	& year==	2008	& a1==	8
			replace v2paid = 	.	if countryid==	14	& year==	2008	& a1==	9
			replace v2paid = 	.	if countryid==	14	& year==	2008	& a1==	11
			replace v2paid = 	1329	if countryid==	14	& year==	2008	& a1==	2
			replace v2paid = 	.	if countryid==	14	& year==	2008	& a1==	10
			replace v2paid = 	1384	if countryid==	14	& year==	2008	& a1==	1
			replace v2paid = 	.	if countryid==	14	& year==	2008	& a1==	12
			replace v2paid = 	.	if countryid==	14	& year==	2008	& a1==	13
			replace v2paid = 	756	if countryid==	7	& year==	2007	& a1==	11
			replace v2paid = 	756	if countryid==	7	& year==	2010	& a1==	11
			replace v2paid = 	.	if countryid==	7	& year==	2010	& a1==	9
			replace v2paid = 	.	if countryid==	7	& year==	2007	& a1==	3
			replace v2paid = 	.	if countryid==	7	& year==	2010	& a1==	3
			replace v2paid = 	622	if countryid==	7	& year==	2010	& a1==	5
			replace v2paid = 	1563	if countryid==	7	& year==	2007	& a1==	4
			replace v2paid = 	1563	if countryid==	7	& year==	2010	& a1==	4
			replace v2paid = 	.	if countryid==	7	& year==	2010	& a1==	6
			replace v2paid = 	.	if countryid==	7	& year==	2007	& a1==	5
			replace v2paid = 	.	if countryid==	7	& year==	2007	& a1==	17
			replace v2paid = 	.	if countryid==	7	& year==	2010	& a1==	17
			replace v2paid = 	.	if countryid==	7	& year==	2010	& a1==	7
			replace v2paid = 	.	if countryid==	7	& year==	2010	& a1==	18
			replace v2paid = 	.	if countryid==	7	& year==	2007	& a1==	18
			replace v2paid = 	789	if countryid==	7	& year==	2007	& a1==	2
			replace v2paid = 	789	if countryid==	7	& year==	2010	& a1==	2
			replace v2paid = 	36	if countryid==	7	& year==	2007	& a1==	12
			replace v2paid = 	36	if countryid==	7	& year==	2010	& a1==	12
			replace v2paid = 	.	if countryid==	7	& year==	2007	& a1==	15
			replace v2paid = 	.	if countryid==	7	& year==	2010	& a1==	19
			replace v2paid = 	500	if countryid==	7	& year==	2007	& a1==	1
			replace v2paid = 	500	if countryid==	7	& year==	2010	& a1==	1
			replace v2paid = 	1680	if countryid==	7	& year==	2007	& a1==	13
			replace v2paid = 	1680	if countryid==	7	& year==	2010	& a1==	13
			replace v2paid = 	1586	if countryid==	7	& year==	2007	& a1==	14
			replace v2paid = 	1586	if countryid==	7	& year==	2010	& a1==	10
			replace v2paid = 	.	if countryid==	7	& year==	2010	& a1==	16
			replace v2paid = 	.	if countryid==	7	& year==	2007	& a1==	16
			replace v2paid = 	.	if countryid==	7	& year==	2010	& a1==	15
			replace v2paid = 	.	if countryid==	7	& year==	2010	& a1==	8
			replace v2paid = 	1739	if countryid==	9	& year==	2008	& a1==	1
			replace v2paid = 	152	if countryid==	9	& year==	2008	& a1==	2
			replace v2paid = 	.	if countryid==	16	& year==	2011	& a1==	15
			replace v2paid = 	.	if countryid==	16	& year==	2011	& a1==	5
			replace v2paid = 	536	if countryid==	16	& year==	2011	& a1==	8
			replace v2paid = 	1022	if countryid==	16	& year==	2011	& a1==	9
			replace v2paid = 	.	if countryid==	16	& year==	2011	& a1==	12
			replace v2paid = 	.	if countryid==	16	& year==	2011	& a1==	16
			replace v2paid = 	.	if countryid==	16	& year==	2011	& a1==	11
			replace v2paid = 	.	if countryid==	16	& year==	2011	& a1==	6
			replace v2paid = 	.	if countryid==	16	& year==	2011	& a1==	10
			replace v2paid = 	1204	if countryid==	16	& year==	2011	& a1==	7
			replace v2paid = 	.	if countryid==	16	& year==	2011	& a1==	14
			replace v2paid = 	.	if countryid==	16	& year==	2011	& a1==	13
			replace v2paid = 	1527	if countryid==	16	& year==	2011	& a1==	1
			replace v2paid = 	379	if countryid==	16	& year==	2011	& a1==	3
			replace v2paid = 	.	if countryid==	16	& year==	2011	& a1==	4
			replace v2paid = 	329	if countryid==	16	& year==	2011	& a1==	2
			replace v2paid = 	533	if countryid==	11	& year==	2011	& a1==	2
			replace v2paid = 	.	if countryid==	11	& year==	2011	& a1==	5
			replace v2paid = 	1040	if countryid==	11	& year==	2011	& a1==	6
			replace v2paid = 	.	if countryid==	11	& year==	2011	& a1==	1
			replace v2paid = 	821	if countryid==	11	& year==	2011	& a1==	3
			replace v2paid = 	110	if countryid==	11	& year==	2011	& a1==	4
			replace v2paid = 	.	if countryid==	11	& year==	2011	& a1==	9
			replace v2paid = 	1150	if countryid==	11	& year==	2011	& a1==	8
			replace v2paid = 	685	if countryid==	11	& year==	2011	& a1==	7
			replace v2paid = 	.	if countryid==	6	& year==	2011	& a1==	10
			replace v2paid = 	901	if countryid==	6	& year==	2011	& a1==	4
			replace v2paid = 	901	if countryid==	6	& year==	2007	& a1==	1
			replace v2paid = 	.	if countryid==	6	& year==	2011	& a1==	11
			replace v2paid = 	.	if countryid==	6	& year==	2007	& a1==	6
			replace v2paid = 	.	if countryid==	6	& year==	2011	& a1==	7
			replace v2paid = 	.	if countryid==	6	& year==	2007	& a1==	9
			replace v2paid = 	.	if countryid==	6	& year==	2007	& a1==	16
			replace v2paid = 	.	if countryid==	6	& year==	2007	& a1==	17
			replace v2paid = 	.	if countryid==	6	& year==	2011	& a1==	17
			replace v2paid = 	479	if countryid==	6	& year==	2011	& a1==	6
			replace v2paid = 	479	if countryid==	6	& year==	2007	& a1==	5
			replace v2paid = 	.	if countryid==	6	& year==	2007	& a1==	13
			replace v2paid = 	.	if countryid==	6	& year==	2007	& a1==	14
			replace v2paid = 	.	if countryid==	6	& year==	2007	& a1==	15
			replace v2paid = 	.	if countryid==	6	& year==	2011	& a1==	13
			replace v2paid = 	7548	if countryid==	6	& year==	2007	& a1==	4
			replace v2paid = 	.	if countryid==	6	& year==	2007	& a1==	10
			replace v2paid = 	.	if countryid==	6	& year==	2011	& a1==	12
			replace v2paid = 	495	if countryid==	6	& year==	2007	& a1==	2
			replace v2paid = 	495	if countryid==	6	& year==	2011	& a1==	1
			replace v2paid = 	.	if countryid==	6	& year==	2007	& a1==	12
			replace v2paid = 	.	if countryid==	6	& year==	2007	& a1==	18
			replace v2paid = 	.	if countryid==	6	& year==	2011	& a1==	9
			replace v2paid = 	.	if countryid==	6	& year==	2007	& a1==	11
			replace v2paid = 	1303	if countryid==	6	& year==	2011	& a1==	2
			replace v2paid = 	1303	if countryid==	6	& year==	2007	& a1==	3
			replace v2paid = 	.	if countryid==	6	& year==	2011	& a1==	14
			replace v2paid = 	.	if countryid==	6	& year==	2007	& a1==	7
			replace v2paid = 	.	if countryid==	6	& year==	2011	& a1==	8
			replace v2paid = 	.	if countryid==	6	& year==	2011	& a1==	16
			replace v2paid = 	1689	if countryid==	6	& year==	2011	& a1==	3
			replace v2paid = 	7548	if countryid==	6	& year==	2011	& a1==	5
			replace v2paid = 	1689	if countryid==	6	& year==	2007	& a1==	8
			replace v2paid = 	.	if countryid==	6	& year==	2011	& a1==	15
			replace v2paid = 	.	if countryid==	3	& year==	2009	& a1==	5
			replace v2paid = 	.	if countryid==	3	& year==	2005	& a1==	5
			replace v2paid = 	1375	if countryid==	3	& year==	2005	& a1==	2
			replace v2paid = 	1375	if countryid==	3	& year==	2009	& a1==	2
			replace v2paid = 	1731	if countryid==	3	& year==	2005	& a1==	3
			replace v2paid = 	1731	if countryid==	3	& year==	2009	& a1==	3
			replace v2paid = 	.	if countryid==	3	& year==	2009	& a1==	6
			replace v2paid = 	573	if countryid==	3	& year==	2005	& a1==	4
			replace v2paid = 	573	if countryid==	3	& year==	2009	& a1==	4
			replace v2paid = 	.	if countryid==	3	& year==	2005	& a1==	6
			replace v2paid = 	383	if countryid==	3	& year==	2005	& a1==	1
			replace v2paid = 	383	if countryid==	3	& year==	2009	& a1==	1
			replace v2paid = 	.	if countryid==	3	& year==	2005	& a1==	7
			replace v2paid = 	794	if countryid==	5	& year==	2009	& a1==	1
			replace v2paid = 	1468	if countryid==	5	& year==	2009	& a1==	2
			replace v2paid = 	1651	if countryid==	5	& year==	2011	& a1==	4
			replace v2paid = 	1660	if countryid==	5	& year==	2011	& a1==	5
			replace v2paid = 	1160	if countryid==	5	& year==	2011	& a1==	6
			replace v2paid = 	794	if countryid==	5	& year==	2011	& a1==	1
			replace v2paid = 	794	if countryid==	5	& year==	2007	& a1==	1
			replace v2paid = 	1468	if countryid==	5	& year==	2007	& a1==	2
			replace v2paid = 	1468	if countryid==	5	& year==	2011	& a1==	2
			replace v2paid = 	301	if countryid==	5	& year==	2011	& a1==	3
			replace v2paid = 	1691	if countryid==	13	& year==	2010	& a1==	1
			replace v2paid = 	42	if countryid==	13	& year==	2010	& a1==	4
			replace v2paid = 	1412	if countryid==	13	& year==	2010	& a1==	2
			replace v2paid = 	1650	if countryid==	13	& year==	2010	& a1==	5
			replace v2paid = 	1408	if countryid==	13	& year==	2010	& a1==	3
			replace v2paid = 	457	if countryid==	12	& year==	2009	& a1==	4
			replace v2paid = 	224	if countryid==	12	& year==	2009	& a1==	6
			replace v2paid = 	363	if countryid==	12	& year==	2009	& a1==	3
			replace v2paid = 	1224	if countryid==	12	& year==	2009	& a1==	5
			replace v2paid = 	964	if countryid==	12	& year==	2009	& a1==	2
			replace v2paid = 	1396	if countryid==	12	& year==	2009	& a1==	1
			replace v2paid = 	1055	if countryid==	4	& year==	2007	& a1==	1
			replace v2paid = 	1288	if countryid==	4	& year==	2007	& a1==	2
			replace v2paid = 	.	if countryid==	4	& year==	2007	& a1==	3
			replace v2paid = 	2735	if countryid==	4	& year==	2007	& a1==	7
			replace v2paid = 	562	if countryid==	4	& year==	2007	& a1==	4
			replace v2paid = 	.	if countryid==	4	& year==	2007	& a1==	5
			replace v2paid = 	4	if countryid==	4	& year==	2007	& a1==	6
			replace v2paid = 	1157	if countryid==	8	& year==	2006	& a1==	1
			replace v2paid = 	.	if countryid==	8	& year==	2006	& a1==	7
			replace v2paid = 	45	if countryid==	8	& year==	2006	& a1==	8
			replace v2paid = 	.	if countryid==	8	& year==	2006	& a1==	6
			replace v2paid = 	298	if countryid==	8	& year==	2006	& a1==	5
			replace v2paid = 	.	if countryid==	8	& year==	2006	& a1==	10
			replace v2paid = 	1234	if countryid==	8	& year==	2006	& a1==	2
			replace v2paid = 	.	if countryid==	8	& year==	2006	& a1==	9
			replace v2paid = 	1363	if countryid==	8	& year==	2006	& a1==	3
			replace v2paid = 	828	if countryid==	8	& year==	2006	& a1==	4
			replace v2paid = 	1310	if countryid==	10	& year==	2009	& a1==	1
			replace v2paid = 	1310	if countryid==	10	& year==	2011	& a1==	1
			replace v2paid = 	1308	if countryid==	10	& year==	2009	& a1==	2
			replace v2paid = 	284	if countryid==	10	& year==	2009	& a1==	3
			replace v2paid = 	655	if countryid==	10	& year==	2009	& a1==	5
			replace v2paid = 	1359	if countryid==	10	& year==	2009	& a1==	4
			replace v2paid = 	1308	if countryid==	10	& year==	2011	& a1==	2
			replace v2paid = 	.	if countryid==	10	& year==	2011	& a1==	4
			replace v2paid = 	.	if countryid==	10	& year==	2011	& a1==	3
			replace v2paid = 	655	if countryid==	10	& year==	2011	& a1==	6
			replace v2paid = 	1359	if countryid==	10	& year==	2011	& a1==	5
			replace v2paid = 	651	if countryid==	15	& year==	2010	& a1==	4
			replace v2paid = 	.	if countryid==	15	& year==	2010	& a1==	6
			replace v2paid = 	.	if countryid==	15	& year==	2010	& a1==	2
			replace v2paid = 	456	if countryid==	15	& year==	2010	& a1==	5
			replace v2paid = 	830	if countryid==	15	& year==	2010	& a1==	9
			replace v2paid = 	1274	if countryid==	15	& year==	2010	& a1==	3
			replace v2paid = 	487	if countryid==	15	& year==	2010	& a1==	7
			replace v2paid = 	409	if countryid==	15	& year==	2010	& a1==	8
			replace v2paid = 	199	if countryid==	15	& year==	2010	& a1==	1
			replace v2paid = 	1415	if countryid==	2	& year==	2011	& a1==	19
			replace v2paid = 	.	if countryid==	2	& year==	2007	& a1==	8
			replace v2paid = 	.	if countryid==	2	& year==	2011	& a1==	8
			replace v2paid = 	.	if countryid==	2	& year==	2007	& a1==	1
			replace v2paid = 	.	if countryid==	2	& year==	2011	& a1==	2
			replace v2paid = 	.	if countryid==	2	& year==	2007	& a1==	10
			replace v2paid = 	.	if countryid==	2	& year==	2011	& a1==	16
			replace v2paid = 	.	if countryid==	2	& year==	2011	& a1==	7
			replace v2paid = 	.	if countryid==	2	& year==	2007	& a1==	9
			replace v2paid = 	360	if countryid==	2	& year==	2007	& a1==	2
			replace v2paid = 	360	if countryid==	2	& year==	2011	& a1==	1
			replace v2paid = 	.	if countryid==	2	& year==	2007	& a1==	15
			replace v2paid = 	.	if countryid==	2	& year==	2007	& a1==	16
			replace v2paid = 	.	if countryid==	2	& year==	2011	& a1==	17
			replace v2paid = 	1759	if countryid==	2	& year==	2007	& a1==	6
			replace v2paid = 	1759	if countryid==	2	& year==	2011	& a1==	10
			replace v2paid = 	.	if countryid==	2	& year==	2007	& a1==	5
			replace v2paid = 	.	if countryid==	2	& year==	2011	& a1==	13
			replace v2paid = 	.	if countryid==	2	& year==	2011	& a1==	6
			replace v2paid = 	.	if countryid==	2	& year==	2007	& a1==	12
			replace v2paid = 	.	if countryid==	2	& year==	2011	& a1==	18
			replace v2paid = 	.	if countryid==	2	& year==	2007	& a1==	7
			replace v2paid = 	.	if countryid==	2	& year==	2011	& a1==	11
			replace v2paid = 	.	if countryid==	2	& year==	2011	& a1==	12
			replace v2paid = 	.	if countryid==	2	& year==	2011	& a1==	9
			replace v2paid = 	.	if countryid==	2	& year==	2007	& a1==	13
			replace v2paid = 	.	if countryid==	2	& year==	2011	& a1==	5
			replace v2paid = 	.	if countryid==	2	& year==	2007	& a1==	11
			replace v2paid = 	.	if countryid==	2	& year==	2011	& a1==	15
			replace v2paid = 	.	if countryid==	2	& year==	2007	& a1==	14
			replace v2paid = 	29	if countryid==	2	& year==	2011	& a1==	3
			replace v2paid = 	.	if countryid==	2	& year==	2007	& a1==	4
			replace v2paid = 	308	if countryid==	2	& year==	2007	& a1==	3
			replace v2paid = 	308	if countryid==	2	& year==	2011	& a1==	4
			replace v2paid = 	177	if countryid==	18	& year==	2006	& a1==	1
			replace v2paid = 	676	if countryid==	18	& year==	2006	& a1==	2
			replace v2paid = 	1728	if countryid==	18	& year==	2006	& a1==	3
			replace v2paid = 	466	if countryid==	18	& year==	2006	& a1==	4
			replace v2paid = 	1554	if countryid==	18	& year==	2006	& a1==	5
			replace v2paid = 	.	if countryid==	21	& year==	2013	& a1==	1
			replace v2paid = 	2280	if countryid==	21	& year==	2013	& a1==	2
			replace v2paid = 	365	if countryid==	21	& year==	2013	& a1==	3
			replace v2paid = 	1221	if countryid==	21	& year==	2013	& a1==	4
			replace v2paid = 	2046	if countryid==	21	& year==	2013	& a1==	5
			replace v2paid = 	802	if countryid==	21	& year==	2013	& a1==	6
			replace v2paid = 	.	if countryid==	21	& year==	2013	& a1==	7
			replace v2paid = 	2281	if countryid==	21	& year==	2013	& a1==	8
			replace v2paid = 	7031	if countryid==	21	& year==	2013	& a1==	9
			replace v2paid = 	.	if countryid==	21	& year==	2013	& a1==	10
			replace v2paid = 	201	if countryid==	21	& year==	2013	& a1==	11
			replace v2paid = 	.	if countryid==	20	& year==	2011	& a1==	6
			replace v2paid = 	1099	if countryid==	20	& year==	2011	& a1==	3
			replace v2paid = 	1049	if countryid==	20	& year==	2011	& a1==	1
			replace v2paid = 	.	if countryid==	20	& year==	2011	& a1==	8
			replace v2paid = 	.	if countryid==	20	& year==	2011	& a1==	5
			replace v2paid = 	1824	if countryid==	20	& year==	2011	& a1==	2
			replace v2paid = 	591	if countryid==	20	& year==	2011	& a1==	4
			replace v2paid = 	.	if countryid==	20	& year==	2011	& a1==	7
			replace v2paid = 	.	if countryid==	19	& year==	2009	& a1==	2
			replace v2paid = 	101	if countryid==	19	& year==	2009	& a1==	7
			replace v2paid = 	.	if countryid==	19	& year==	2009	& a1==	6
			replace v2paid = 	705	if countryid==	19	& year==	2009	& a1==	4
			replace v2paid = 	1072	if countryid==	19	& year==	2009	& a1==	3
			replace v2paid = 	719	if countryid==	19	& year==	2009	& a1==	1
			replace v2paid = 	1173	if countryid==	19	& year==	2009	& a1==	5
			replace v2paid = 	5940	if countryid==	17	& year==	2012	& a1==	9
			replace v2paid = 	2473	if countryid==	17	& year==	2012	& a1==	8
			replace v2paid = 	.	if countryid==	17	& year==	2012	& a1==	3
			replace v2paid = 	660	if countryid==	17	& year==	2012	& a1==	6
			replace v2paid = 	1750	if countryid==	17	& year==	2012	& a1==	7
			replace v2paid = 	481	if countryid==	17	& year==	2012	& a1==	2
			replace v2paid = 	2474	if countryid==	17	& year==	2012	& a1==	11
			replace v2paid = 	120	if countryid==	17	& year==	2012	& a1==	1
			replace v2paid = 	1105	if countryid==	17	& year==	2012	& a1==	10
			replace v2paid = 	1541	if countryid==	17	& year==	2012	& a1==	4
			replace v2paid = 	5941	if countryid==	17	& year==	2012	& a1==	5
			replace v2paid = 	.	if countryid==	23	& year==	2010	& a1==	8
			replace v2paid = 	1567	if countryid==	23	& year==	2010	& a1==	2
			replace v2paid = 	.	if countryid==	23	& year==	2010	& a1==	9
			replace v2paid = 	.	if countryid==	23	& year==	2010	& a1==	5
			replace v2paid = 	1516	if countryid==	23	& year==	2010	& a1==	1
			replace v2paid = 	1388	if countryid==	23	& year==	2010	& a1==	3
			replace v2paid = 	.	if countryid==	23	& year==	2010	& a1==	11
			replace v2paid = 	.	if countryid==	23	& year==	2010	& a1==	10
			replace v2paid = 	601	if countryid==	23	& year==	2010	& a1==	4
			replace v2paid = 	.	if countryid==	23	& year==	2010	& a1==	7
			replace v2paid = 	986	if countryid==	23	& year==	2010	& a1==	6

		****************************
		***** Merge data sets ******
		****************************
			sort v2paid year
			merge v2paid year using "$dir\vdem-parties-merge.dta"
			drop if _merge==2
			keep if v2paid~=.  
			rename _merge mergeA1
			sort v2paid year
			merge v2paid year using "$dir\pers-use.dta"
			drop if _merge==2
			rename _merge mergeA2
		
		***********************
		*** More variables ***
		**********************
			qui reg partytime v2paind
			gen s=e(sample)
			egen surveyid =group(year countryid) if s==1
			egen idcyp = group(year countryid v2paid) if s==1
			replace partytime=partytime+1
			egen psize = count(year) if s==1,by(v2paid)
			drop partyage
			gen partyage = pminyear-year
			recode e6a (1 2 3 =1) (4 5 6 =2) (7=3) (8 99 =0) (.a .b =-1),gen(education)
			qui sum v2paind
			replace v2paind  = (v2paind+(abs(r(min)))) / (abs(r(min))+r(max))
			 
		*************************************************************
		*** Create individual-level political experience measures ***
		*************************************************************
			 desc a9a a9b a9c  a9e a9f a9g
			 desc a8a a8b a8c
			 egen xyrsgov =rowmax(a9a a9b a9c  a9e a9f a9g)
			 egen xyrsparty =rowmax(a8a a8b a8c)
			 gen lnxyrsgov = ln(1+ xyrsgov)
			 gen lnxyrsparty = ln(1+xyrsparty)
			 
		***************************************
		*** Some descriptive plots          ***
		*** Fidesz appears to be an outlier ***
		***************************************
			twoway (lpolyci  xyrsparty v2paind,bw(.1)col(blue)yaxis(2)) ///
				(lpolyci  xyrsgov v2paind,bw(.1)col(green)yaxis(2)   ///
				legend(lab(1 "Party experience")lab(3 "Government experience") ///
				 order(1 3)ring(0)pos(7)) ///
				xtit(Party personalism)ytit("Years experience",axis(2)))
				
			twoway (lpolyci  xyrsparty v2paind if v2paid~=1691,bw(.1)col(blue)yaxis(2)) ///
				(lpolyci  xyrsgov v2paind if v2paid~=1691,bw(.1)col(green)yaxis(2)   ///
				legend(lab(1 "Party experience")lab(3 "Government experience") ///
				 order(1 3)ring(0)pos(7)) ///
				xtit(Party personalism)ytit("Years experience",axis(2)))
		 
			twoway (lpoly xyrsparty v2paind,bw(.1)col(blue)) ///
				(lpoly xyrsparty v2paind if v2paid~=1691,bw(.1)col(red) ///
				xlab(0(.2)1)legend(lab(1 "All parties")lab(2 "All but Fidesz")order(1 2) ///
				ring(0)pos(7))tit(Fidesz is an outlier) ///
				xtit(Party personalism)ytit(Elite experience,height(-3)))

		*************************************
		*** Candidate experience Analysis ***
		*************************************
					drop id 
					egen id=group(countryid year)
					sum id
					gen govexp = round(xyrsgov,1)
					gen parexp = round(xyrsparty,1)
					gen opposition= v2pagovsup==3 if v2pagovsup~=.
					global d = "v2paind"
					* Baseline reported model *
					xtnbreg govexp $d,i(id) 
					predict cnt1 if e(sample)==1,nu0
					
					** Model specification checks *
					xtnbreg govexp $d,i(countryid) 
					xtnbreg govexp $d age male,i(id) 
					xi:xtnbreg govexp $d age male i.education,i(id) 
					xi:xtnbreg govexp $d age male i.education v2paseat opposition,i(id) 
					xi:xtnbreg govexp $d age male i.education v2paseat opposition incentive,i(id) 
					predict cnt2 if e(sample)==1,nu0
					
					* Drop Fidez outlier *
					xi:xtnbreg govexp $d if v2paid~=1691,i(id) 
					xi:xtnbreg govexp $d age male i.education v2pasea opposition incentive if v2paid~=1691,i(id) 

					* Within estimators *
					xi:xtnbreg govexp $d age male i.education v2paseat opposition incentive,i(id) fe
					xi:nbreg govexp i.id $d age male i.education v2paseat opposition,
					predict cnt3 if e(sample)==1,n
					
					* Multi-level *
					xi:meglm govexp i.year $d incentive opposition v2paseats || countryid:, family(nbinomial)
					xi:meglm govexp i.year $d age male i.education incentive opposition v2paseats || countryid:, family(nbinomial)

					* Among candidates and non-candidates
					xtnbreg govexp $d age if candidate==0,i(id) 
					xtnbreg govexp $d age if candidate==1,i(id) 

					* Party experience *
					xtnbreg parexp $d,i(id) 
					predict cnt4,nu0
					xi:xtnbreg parexp $d age male i.education v2paseat opposition incentive,i(id) 
					predict  cnt5 if e(sample),nu0
					xi:nbreg parexp i.countryid $d age male i.education v2paseat opposition incentive,
					predict  cnt6 if e(sample),n
					
					* Different types of party positions *
					local var = "a b c"
					foreach v of local var {
						desc a8`v'
						qui xtnbreg a8`v' $d age,i(id) 
						lincom $d
						qui xi:xtnbreg a8`v' $d age male i.education v2paseat opposition incentive,i(id) 
						lincom $d
						qui xi:nbreg a8`v' i.id $d age male i.education v2paseat opposition incentive
						lincom $d
					}

					* How long a member of the party *
					xtnbreg partytime $d,i(id) 
					xtnbreg partytime $d age,i(id) 
					predict cnt7,nu0
					xi:xtnbreg partytime $d age male i.education v2paseat opposition incentive,i(id) 
					xi:nbreg partytime i.id $d age male i.education v2paseat opposition incentive,
					predict  cnt8 if e(sample),n

					twoway (lpolyci cnt1 v2paind,bw(.2)) (lpolyci cnt2 v2paind,bw(.2)lcol(gs1) ///
						legend(lab(2 "Baseline count")lab(3 "Adjusted count") ///
						lab(5 "Within count")pos(7)ring(0)col(1)order(2 3 5))xtit(Party personalism) ///
						ytit(Years of experience)ylab(2(1)9)tit(Government experience) ///
						saving("h1.gph",replace)) (lpolyci cnt3 v2paind,bw(.2)lcol(gs12) )
					twoway (lpolyci cnt4 v2paind,bw(.2)) (lpolyci cnt5 v2paind,bw(.2)lcol(gs1) ///
						legend(lab(2 "Baseline count")lab(3 "Adjusted count") ///
						lab(5 "Within count")pos(7)ring(0)col(1)order(2 3 5))xtit(Party personalism) ///
						ytit(Years of experience)ylab(4(2)12)tit(Party experience) ///
						saving("h2.gph",replace)) (lpolyci cnt6 v2paind,bw(.2)lcol(gs12) )
					gr combine h1.gph h2.gph,xsize(8)tit("Elites' experience, Comparative Candidate Survey")
					gr export "$dir\golden\Ch3-CCS-elite-experience.pdf",as(pdf)replace 
					erase h1.gph
					erase h2.gph
					drop cnt*

			*********************************************************************************
			**** Comparing experience of candidates from personalist and populist parties ***
			*********************************************************************************
				qui centile v2xpa_popul if parexp~=.,centile(50)
				local c = r(c_1)
				gen hipop = v2xpa_popul>`c' if v2xpa_popul~=.
				qui centile v2paind if parexp~=.,centile(50)
				local c = r(c_1)
				gen hipers = v2paind>`c' if v2paind~=.
				egen ptag = tag(v2paid) if hipers~=.
				tab hipers hipop 
				tab hipers hipop if ptag==1
				gen e = .
				gen hi = . 
				gen lo = .
				gen n = _n
				ttest govexp,by(hipers)
				local  m1=r(mu_1) 
				local se1 = r(sd_1)/(sqrt(r(N_1)))
				local  m2=r(mu_2)
				local se2 = r(sd_2)/(sqrt(r(N_2)))
				replace e=`m1' if _n==1
				replace hi = `m1' + 1.95* `se1' if _n==1
				replace lo = `m1' - 1.95* `se1'  if _n==1
				replace e=`m2' if _n==2
				replace hi = `m2' + 1.95*`se2' if _n==2
				replace lo = `m2' - 1.95*`se2' if _n==2	
				ttest govexp,by(hipop)
				local  m1=r(mu_1) 
				local se1 = r(sd_1)/(sqrt(r(N_1)))
				local  m2=r(mu_2)
				local se2 = r(sd_2)/(sqrt(r(N_2)))
				replace e=`m1' if _n==4
				replace hi = `m1' + 1.95* `se1' if _n==4
				replace lo = `m1' - 1.95* `se1'  if _n==4
				replace e=`m2' if _n==5
				replace hi = `m2' + 1.95*`se2' if _n==5
				replace lo = `m2' - 1.95*`se2' if _n==5	
				twoway (bar e n if n<=5,barwidth(.5)bcol(gs13)ytit("Years of experience")saving(h1.gph,replace)) ///
					(rspike hi lo n if n<=5,ylab(0(2)6)col(gs1)legend(off)xtit("")tit(Government experience) ///
					xlab(1 `""{bf:Low} party" "personalism""' 2 `""{bf:High} party" "personalism""' ///
					4 `""{bf:Low} party" "populism""' 5  `""{bf:High} party" "populism""')xscale(range(0.5 5.5)))
				ttest parexp,by(hipers)
				local  m1=r(mu_1) 
				local se1 = r(sd_1)/(sqrt(r(N_1)))
				local  m2=r(mu_2)
				local se2 = r(sd_2)/(sqrt(r(N_2)))
				replace e=`m1' if _n==1
				replace hi = `m1' + 1.95* `se1' if _n==1
				replace lo = `m1' - 1.95* `se1'  if _n==1
				replace e=`m2' if _n==2
				replace hi = `m2' + 1.95*`se2' if _n==2
				replace lo = `m2' - 1.95*`se2' if _n==2	
				ttest parexp,by(hipop)
				local  m1=r(mu_1) 
				local se1 = r(sd_1)/(sqrt(r(N_1)))
				local  m2=r(mu_2)
				local se2 = r(sd_2)/(sqrt(r(N_2)))
				replace e=`m1' if _n==4
				replace hi = `m1' + 1.95* `se1' if _n==4
				replace lo = `m1' - 1.95* `se1'  if _n==4
				replace e=`m2' if _n==5
				replace hi = `m2' + 1.95*`se2' if _n==5
				replace lo = `m2' - 1.95*`se2' if _n==5	
				twoway (bar e n if n<=5,barwidth(.5)bcol(gs13)ytit("Years of experience")saving(h2.gph,replace)) ///
					(rspike hi lo n if n<=5,ylab(3(3)9)col(gs1)legend(off)xtit("")tit(Party experience) ///
					xlab(1 `""{bf:Low} party" "personalism""' 2 `""{bf:High} party" "personalism""' ///
					4 `""{bf:Low} party" "populism""' 5  `""{bf:High} party" "populism""')xscale(range(0.5 5.5)))
				gr combine h1.gph h2.gph,xsize(8)tit(Candidate experience)note("Comparative Candidate Survey data.",size(vsmall))
				gr export "$dir\golden\Ch3-CCS-elite-experience-pers-pop.pdf",as(pdf)replace 
					
				* Adjust for party populism *
				xi:xtnbreg govexp $d opposition v2paseats v2xpa_popul,i(id) 
				xi:xtnbreg govexp $d age v2xpa_popul,i(id) 
				xi:xtnbreg govexp $d opposition v2paseats age v2xpa_popul,i(id) 
				xi:xtnbreg govexp $d age male i.education v2paseat opposition incentive v2xpa_popul,i(id)
				est store p1
				xi:xtnbreg govexp $d age male i.education v2paseat opposition incentive v2xpa_popul,i(id)fe 
				xi:xtnbreg parexp $d v2xpa_popul,i(id) 
				xi:xtnbreg parexp $d opposition v2paseats v2xpa_popul,i(id)
				xi:xtnbreg parexp $d age v2xpa_popul,i(id) 
				xi:xtnbreg parexp $d opposition v2paseats age v2xpa_popul,i(id) 
				xi:xtnbreg parexp $d age male i.education v2paseat opposition incentive v2xpa_popul,i(id) 
				est store p2
				xi:xtnbreg parexp $d age male i.education v2paseat opposition incentive v2xpa_popul,i(id)fe 
				label var male "Male candidate"
				label var age "Candidate age"
				label var opposition "Opposition party"
				label var v2paseats "# of legislative seats"
				label var v2paind "Party {bf:personalism}"
				label var v2xpa_popul "Party {bf:populism}"
				label var incentive `""Institutional incentive to" "cultivate personal vote""'
				coefplot (p1, msymbol(D)mfcolor(gs1))(p2,mfcolor(gs8)msymbol(circle)), order(v2paind v2xpa_popul)  ///
						drop(_cons _Ieducation_*) xline(0) msymbol(d) mfcolor(white) grid(glcolor(gs15)) ///
						levels(95 90) legend(lab(3 "Government experience")lab(6 "Party experience") order(3 6 ) ///
						size(small) pos(6) col(4) ring(1)) xsize(2) ysize(2) xlab(-1(.5).5)  ///
						xtitle("        Coefficient estimate", size(small))  ///
						ciopts(lwidth(thin)) aspectratio(1) scale(.85)  ///
						title(Candidate experience, size(large) height(3)) ///
						note("Estimates for candidate education level not reported.", size(vsmall)pos(6))  
				gr export "$dir\golden\T-CCS-elite-experience-pers-pop.pdf",as(pdf)replace 


		************************************************************************************
		*** Personalist party candidates more likely to be nominated by party leadership ***
		************************************************************************************
			gen leadernom = 1 if b3a==5
			replace leadernom = 0 if b3a==1 |  b3a==2 | b3a==3 | b3a==4 |   b3a==7
			tab b3a leadernom
			
			* Multilevel reported model *
			xi:meglm leadernom $d || countryid: ,fam(binomial)link(probit)
			margins,dydx(v2paind)
			xi:meglm leadernom $d age || countryid: ,fam(binomial)link(probit)
			margins,dydx(v2paind)
			xi:meglm leadernom $d age male i.education || countryid:,fam(binomial)link(probit)
			margins,dydx(v2paind)
				* reported estimate: 25 % *
			xi:meglm leadernom $d age male i.education v2paseat opposition incentive ///
				|| countryid:,fam(binomial)link(probit)
			margins,dydx(v2paind)
			xi:meglm leadernom $d age male i.education v2paseat opposition incentive v2xpa_popul ///
				|| countryid:,fam(binomial)link(probit)
			margins,dydx(v2paind v2xpa_popul)

			* Hybrid model *
			xthybrid leadernom $d,clusterid(countryid)p cre

			* Plot substantive effect from baseline model as partials *
			qui reg $d i.idcyp
			qui predict x if e(sample)==1,xb
			qui reg leadernom   i.idcyp
			qui predict y if e(sample)==1,xb
			qui sum x
			qui replace x=(x+abs(r(min)))/(abs(r(min))+r(max))
			qui sum y
			qui replace y=(y+abs(r(min)))/(abs(r(min))+r(max))
			sum x y
			twoway lpoly y x,legend(off)xtit("Party personalism (partial)") ///
				ytit("Party elite experience (partial)",)bw(.3) ///
				tit(Elites in more personalist parties are more likely to be nominated by leader)
			drop x y

			** Model specification checks in a CRE probit *
			xi:xthybrid leadernom $d age,clusterid(countryid)p cre
			xi:xthybrid leadernom $d age male,clusterid(countryid)p cre
			xi:xthybrid leadernom $d age male i.education,clusterid(countryid)p cre
 			xi:xthybrid leadernom $d age male i.education v2paseat opposition incentive,clusterid(countryid)p cre

			* Within estimators *
			reg leadernom $d   
			xtreg leadernom $d,i(countryid)  
			xtreg leadernom $d,fe i(countryid) 
			xi:reghdfe leadernom $d age male i.education v2paseat opposition,a(countryid) cluster(v2paid)
			
			* Among candidates and non-candidates
			xthybrid leadernom $d if candidate==0,clusterid(countryid)p cre
			xthybrid leadernom $d if candidate==1,clusterid(countryid)p cre
			
			* Compare only ruling parties using original party personalism *
			xi:krls leadernom persparty age male i.education v2paseat opposition incentive v2xpa_popul
			
			
		
***********************************
***** Cabinet tenure analysis *****
***********************************	
		use "$dir\pers-use.dta",clear
		sort cowcode year
		save, replace
		/*
		import excel "WhoGov_crosssectional_V1.2.xlsx",firstrow clear
		destring year,replace
		keep if year>=1989
		save whogov,replace
		*/
		use "$dir\whogov.dta",clear
		gen country = country_name
		gen cowcode =.
		qui do cowcodes
		replace cowcode = 484 if country_name=="Congo - Brazzaville"
		replace cowcode = 490 if country_name=="Congo - Kinshasa"
		replace cowcode = 437 if country_name=="Côte d'Ivoire"
		replace cowcode = 316 if country_name=="Czechia"
		tab country if cowcode==.
		drop if cowcode==.
		drop country
		rename country_name whogov_country 
		sort cowcode year
		merge cowcode year using "$dir\pers-use.dta"
		tab _merge
		tab country if _merge==2  & year<2017
		 gen repeat=year==year[_n-1] if cowcode==cowcode[_n-1]
		 drop if repeat
		 drop repeat
		 drop if _merge==1
		 tsset cowcode year
		 rename _merge mergeA
		 tsset cowcode year
		 merge cowcode year using leadermatch
		 tab _merge
		 drop _merge  

		   * Variables *
		gen tenure = average_core 
		gen election = v2xel_elecpres==1 | v2xel_elecparl==1
		xtset cowcode year
		gen f1election = f1.election
		gen l1election = l.election
		gen l2election = l2.election
		gen postelection = l1election==1 | l2election==1
		gen corenum = ln(n_core)
		swilk n_core corenum
		gen coremil = ln(1+n_militarytitle_core)
		gen anymil = n_militarytitle_core>=1 if n_militarytitle_core~=.
		replace ivdem = ivdem*10  /* rescale to plot point estimate */
		 
			* T-tests with create party *
				gen e = .
				gen hi = . 
				gen lo = .
				gen n = _n
		ttest tenure if leadermatch==1,by(create)
		ttest average_core if leadermatch==1,by(create)
		local  m1=r(mu_1) 
		local se1 = r(sd_1)/(sqrt(r(N_1)))
		local  m2=r(mu_2)
		local se2 = r(sd_2)/(sqrt(r(N_2)))
		replace e=`m1' if _n==1
		replace hi = `m1' + 1.96* `se1' if _n==1
		replace lo = `m1' - 1.96* `se1'  if _n==1
		replace e=`m2' if _n==2
		replace hi = `m2' + 1.96*`se2' if _n==2
		replace lo = `m2' - 1.96*`se2' if _n==2	
		twoway (bar e n if n<=2,barwidth(.5)bcol(gs13)ytit("Average tenure (years)")saving(h1.gph,replace)) ///
			(rspike hi lo n if n<=2,ylab(2(.5)4)col(gs1)legend(off)xtit("")tit(Core appointees) ///
			xlab(1 "No party creation" 2 "Leader creates party")xscale(range(.8 2.2)))
		ttest average_min if leadermatch==1,by(create)
		local  m1=r(mu_1) 
		local se1 = r(sd_1)/(sqrt(r(N_1)))
		local  m2=r(mu_2)
		local se2 = r(sd_2)/(sqrt(r(N_2)))
		replace e=`m1' if _n==1
		replace hi = `m1' + 1.96* `se1' if _n==1
		replace lo = `m1' - 1.96* `se1'  if _n==1
		replace e=`m2' if _n==2
		replace hi = `m2' + 1.96*`se2' if _n==2
		replace lo = `m2' - 1.96*`se2' if _n==2	
		twoway (bar e n if n<=2,barwidth(.5)bcol(gs13)ytit("Average tenure (years)")saving(h2.gph,replace)) ///
			(rspike hi lo n if n<=2,ylab(2(.5)4)col(gs1)legend(off)xtit("")tit(Ministerial appointees) ///
			xlab(1 "No party creation" 2 "Leader creates party")xscale(range(.8 2.2)))
		ttest average_tot if leadermatch==1,by(create)
		local  m1=r(mu_1) 
		local se1 = r(sd_1)/(sqrt(r(N_1)))
		local  m2=r(mu_2)
		local se2 = r(sd_2)/(sqrt(r(N_2)))
		replace e=`m1' if _n==1
		replace hi = `m1' + 1.95* `se1' if _n==1
		replace lo = `m1' - 1.95* `se1'  if _n==1
		replace e=`m2' if _n==2
		replace hi = `m2' + 1.95*`se2' if _n==2
		replace lo = `m2' - 1.95*`se2' if _n==2	
		twoway (bar e n if n<=2,barwidth(.5)bcol(gs13)ytit("Average tenure (years)")saving(h3.gph,replace)) ///
			(rspike hi lo n if n<=2,ylab(2(.5)4)col(gs1)legend(off)xtit("")tit(All appointees) ///
			xlab(1 "No party creation" 2 "Leader creates party")xscale(range(.8 2.2)))
		gr combine h1.gph h2.gph h3.gph, xsize(4)ysize(2)col(3)
		gr export "$dir\golden\Ch3-Cabinet-Tenure-By-Create.pdf",as(pdf)replace 
		erase h1.gph
		erase h2.gph
		erase h3.gph
		drop e n hi lo

			* Check t-tests within-country *
		local var ="average_core average_total average_min"
		foreach v of local var {	
			qui reghdfe `v' create,a(cowcode)cluster(lid)
			lincom create
		}

		 * No covariate specification *
		reghdfe tenure persparty if leadermatch==1,vce(cluster lid)a(xperiod*)
		est store tenure0
				
		 * Partial regression plot *
		xi:qui reg average_core i.leadertime ld ivdem pres i.v2elparlel postelection n_party corenum xperiod* if leadermatch==1
		qui predict y1 if e(sample),res
		xi:qui reg persparty i.leadertime ld ivdem pres i.v2elparlel postelection n_party corenum xperiod* if leadermatch==1
		qui predict x1 if e(sample),res
		sum y1 average_core if leadermatch==1
		gen yhat = (3.33+y1)^1.07
		sum y1 yhat average_core if leadermatch==1
		qui sum x1 
		replace x1 = (x1 + abs(r(min)))/(abs(r(min))+ r(max))
		twoway (lpolyci yhat x1,degree(1)level(90) bw(.15)legend(off)xtitle("Ruling party personalism, partial") ///
			ytit("Cabinet tenure years, partial")ylab(2(1)5)) (lowess yhat x1,lcol(gs1)lpat(dash)legend(off))
		drop x1 y1 yhat
		gr export "$dir\golden\Ch3-Pers-Party-Cabinet-Tenure.pdf",as(pdf)replace 

		 * Specifications to report *
		reghdfe tenure ld ivdem persparty if leadermatch==1,vce(cluster lid)a(year leadertime)
		est store tenure1
		xi:reghdfe tenure ld ivdem persparty pres i.v2elparlel postelection n_party corenum ///
			if leadermatch==1,vce(cluster lid)a(year leadertime)
		est store tenure2
		reghdfe tenure ld ivdem persparty postelection if leadermatch==1,vce(cluster lid)a(cowcode year leadertime)
		est store tenure3

		  * Additional specifications *
		reghdfe tenure ld ivdem persparty i_pop pres i.v2elparlel postelection n_party corenum if leadermatch==1,vce(cluster lid)a(year leadertime)
		xi:reghdfe average_total ld ivdem persparty pres i.v2elparlel postelection n_party corenum if leadermatch==1,vce(cluster lid)a(year leadertime)
		est store tenure4
		xi:reghdfe average_minister ld ivdem persparty pres i.v2elparlel postelection n_party corenum if leadermatch==1,vce(cluster lid)a(year leadertime)
		est store tenure5
		
		 * Stronger in presidential + parl-majority *
		 gen sqtenure = tenure^(1/2)
		 swilk tenure sqtenure if leadermatch==1
		xi:reghdfe sqtenure ld ivdem persparty i.v2elparlel postelection n_party corenum ///
			if leadermatch==1 & (pres==1 | (pres==0 & v2paseat>=50 & v2paseat~=.)),vce(cluster lid)a(year leadertime)
		xi:reghdfe sqtenure ld ivdem persparty i.v2elparlel postelection n_party corenum ///
			if leadermatch==1 & (pres==0 & v2paseat<50 & v2paseat~=.),vce(cluster lid)a(year leadertime)	
		xi:interflex sqtenure persparty v2paseat ld ivdem i.v2elparlel postelection n_party corenum  ///
			if leadermatch==1 & (pres==0), cluster(lid)fe(year leadertime)cut(45)
			mat list r(estBin)
 			
		 * Plot estimates *
		label  var _Iv2elparle_1  `""Majoritarian" "(Proportional)""'
		label  var _Iv2elparle_2   `""Mixed     " "(Proportional)""'
		label  var ld  "Democracy age"
		label  var ivdem `""Initial democracy"     "level         ""'
		label  var persparty  "{bf:Party personalism}"
		label  var pres  `""Presidential  " "(Parliamentary)""'
		label  var postelection  "Post-election"
		label  var n_party "# of parties"
		label  var party_share "Party share"
		label  var corenum "# of positions"
		coefplot (tenure1, msymbol(d))(tenure2, msymbol(P)) (tenure3, msymbol(T)), order(persparty ld ivdem postelection)  ///
			drop(_cons _Iv2elparle_3) xline(0) msymbol(d) mfcolor(white) grid(glcolor(gs15)) ///
			levels(95 90) legend(lab(3 "Baseline")lab(6 "Covariate adjustment") lab(9 "Within comparison")order(3 6 9) ///
			size(small) pos(6) col(3) ring(1)) xsize(2) ysize(2) xlab(-1.5(.5)1)  ///
			xtitle("        Coefficient estimate", size(small))  ///
			ciopts(lwidth(thin)) aspectratio(1.1) scale(.75) title(Cabinet appointee tenure, size(medium) height(2))
		gr export "$dir\golden\Ch3-Pers-Party-Cabinet-Tenure-Estimates.pdf",as(pdf)replace 
		
		
		coefplot (tenure4, msymbol(d))(tenure2, msymbol(T))(tenure5, msymbol(P)), order(persparty ld ivdem postelection)  ///
			drop(_cons _Iv2elparle_3) xline(0)  mfcolor(white) grid(glcolor(gs15)) ///
			levels(95 90) legend(lab(3 "All appointees")lab(6 "Core elite") lab(9 "Cabinet members only") order(3 6 9) ///
			size(small) pos(6) col(3) ring(1)) xsize(2) ysize(2) xlab(-1.5(.5)1)  ///
			xtitle("        Coefficient estimate", size(small))  ///
			ciopts(lwidth(thin)) aspectratio(1.1) scale(.75) title(Cabinet appointee tenure, size(medium) height(2))
		gr export "$dir\golden\T-WhoGov-Cabinet-Tenure-Estimates.pdf",as(pdf)replace 
		
		 * Retention rate, core *
		 gen retain = retention_rate_core
		 gen retain2 = retention_rateadj_core
		 recode retain retain2 (0=.001) (1=.999)
		 sum retain retain2 if leadermatch==1
		 betareg retain i.year ld ivdem persparty pres i.v2elparlel postelection n_party corenum ///
			if leadermatch==1,vce(cluster lid)link(loglog)slink(log)
		 betareg retain2 i.year ld ivdem persparty pres i.v2elparlel postelection n_party corenum ///
			if leadermatch==1,vce(cluster lid)link(loglog)slink(log)

 ************** THE END ******************

log close
	
 
	
